﻿using Chaliy.DbPro.Generators;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Chaliy.DbPro.Generators.Tests.Mocks;
using Microsoft.VisualStudio.TeamSystem.Data.DataGenerator;

namespace Chaliy.DbPro.Generators.Tests
{
    
    
    /// <summary>
    ///This is a test class for LoremGeneratorTest and is intended
    ///to contain all LoremGeneratorTest Unit Tests
    ///</summary>
	[TestClass()]
	public class TextGeneratorTests
	{
		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]
		public void OnGetOutputValueTestFixedLength()
		{
			TextGenerator target = TextGeneratorTests.CreateOne();

			target.MaximumLength = 20;
			target.MinimumLength = 20;

			string actual = TextGeneratorTests.Execute(target);

			Assert.AreEqual(20, actual.Length);
		}

		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]
		public void OnGetOutputValueTestRandom()
		{
			TextGenerator target = TextGeneratorTests.CreateOne();

			target.MaximumLength = 20;
			target.MinimumLength = 0;

			string actual = TextGeneratorTests.Execute(target);

			Assert.IsTrue(
				actual.Length < 20 && actual.Length >= 0,
				"Actual lenth must be between 0 and 20"
			);
		}

		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]
		public void OnGetOutputValueTestZeroLength()
		{
			TextGenerator target = TextGeneratorTests.CreateOne();

			target.MaximumLength = 0;
			target.MinimumLength = 0;

			string actual = TextGeneratorTests.Execute(target);

			Assert.IsTrue(
				actual.Length == 0,
				"Actual lenth must be 0"
			);
		}

		private static TextGenerator CreateOne()
		{
			return new MockTextGenerator { TextAuthor = new MockTextAuthor() };
		}

		private static string Execute(TextGenerator generator)
		{
			generator.Initialize(new GeneratorInit(null));
			generator.GenerateNextValues();
			return generator.Result;
		}
	}
}
